using Blog2025.Api.Dto;
using Blog2025.Application.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace Blog2025.Api.Controllers;

[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{
    // 身份验证控制器
    private readonly AuthService _authService;
    public AuthController(AuthService authService)
    {
        _authService = authService;
    }
    [HttpPost("register")]
    public async Task<IActionResult> Register(UserRegisterDto userRegisterDto)
    {
        await _authService.RegisterAsync(userRegisterDto.Username, userRegisterDto.Password);
        return Ok("注册成功");
    }

    [HttpPost("login")]
    public async Task<IActionResult> Login(UserLoginDto userLoginDto)
    {
        var res = await _authService.LoginAsync(userLoginDto.Username, userLoginDto.Password);
        // if (user == null) return Unauthorized("用户名或密码错误");
        return Ok(res);
    }    
}